<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/messages.jsp"%>
<%@ include file="/commons/commonEdit.jsp" %>
<%@ include file="/commons/validation.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script language="JavaScript"  src="${ctx}/scripts/div/common.js"></script>
<script language="JavaScript" type="text/javascript">
var flag = null;
var sourceValue = null;
function ajaxSubmit(){
		var isTrue=$('reasonForm').fireEvent("onSubmit");
	    if(isTrue){
	    	if(flag == "add")
	         	var url = "${ctx}/house_partnershipAction.do?method=addReason";
	        else if(flag == "update")
	            var url = "${ctx}/house_partnershipAction.do?method=editReason";
	        var param = Form.serialize('reasonForm');
	                new Ajax.Request(url,{method: 'post',
					parameters :param ,
					onSuccess : function(response) {
	                 if('true' == response.responseText.strip())
				     {
						 var obj=findFrame('main');
						// if(flag == "add")
							//obj.freshListWithoutCondition('copyMeter');
					    // else
					       obj.freshListWithCondition('copyMeter');
					     windowClose();
				   	 }
					}});

		}
}

function ajaxSubmitAgain(){
		var isTrue=$('reasonForm').fireEvent("onSubmit");
	    if(isTrue){
         	if(flag == "add")
	         	var url = "${ctx}/house_partnershipAction.do?method=addReason";
	        else if(flag == "update")
	            var url = "${ctx}/house_partnershipAction.do?method=editReason";
        	var param = Form.serialize('reasonForm');
                new Ajax.Request(url,{method: 'post',
				parameters :param ,
				onSuccess : function(response) {
                 if('true' == response.responseText.strip())
			     {
					 var obj=findFrame('main');
					 //if(flag == "add")
						//obj.freshListWithoutCondition('copyMeter');
				    // else
				       obj.freshListWithCondition('copyMeter');
				    location.reload();
			   	 }
				}});
		}
}
function closeWin(){
	var newValue=$('reasonForm').serialize();
	if(sourceValue==newValue){
		windowClose();
	}else{
		var result=confirm("是否要保存并退出？");
		//AlarmConfirm('是否要保存并退出？',"main","ajaxSubmit");
		if(result){
			ajaxSubmit();
			return;
		}else{
			windowClose();
		}
	}
}

</script>
</head>

<body onload="init('${editFlag}')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"> <span class="window_head_intext" id="copyMeter_title"></span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td valign="middle" class="content"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="container_in_show">
      <tr>
        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab_subMenu1">
            <tr>
              <td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
                  <tr>
                    <td>
                       <form id="reasonForm" method="post" action="" class="required-validate">
					   <input type="hidden" name="types" value="copyMeter">
					   <input type = "hidden" id="oldType" value="copyMeter">
                       <input type="hidden" id="oldId" name="id" value="${reason.id}">
                       <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
                        <tr>
                          <c:choose>
                        		<c:when test="${editFlag=='add'}">
                        			<td valign="top" class="aux_intable_td1">${key.exceptionName}：</td>
                         			<td class="aux_intable_require_more"><input name="name" type="text" class="required validate-char validate-ajax" relativeId="oldId,oldType" validateUrl=""   size="16" maxlength="100" value="${reason.name}"/> </td>
                        		</c:when>
                        		<c:when test="${editFlag=='update'}">
                        		   <c:choose>
                        		   		<c:when test="${isRefer}">
                        		   			<td valign="top" class="aux_intable_td1">${key.exceptionName}：</td>
                          					<td class="aux_intable_td2"><input name="name" type="hidden" value="${reason.name}"/> ${reason.name}</td>
                        		   		</c:when>
                        		   		<c:otherwise>
                        		   			<td valign="top" class="aux_intable_td1">${key.exceptionName}：</td>
                          					<td class="aux_intable_require_more"><input name="name" type="text" class="required validate-char validate-ajax" relativeId="oldId,oldType" validateUrl=""   size="16" maxlength="100" value="${reason.name}"/> </td>
                        		   		</c:otherwise>
                        		   </c:choose>
                        		</c:when>
                            </c:choose>
                        </tr>
                        <tr>
                          <td valign="top" class="aux_intable_td1">${key.exceptionDescription}：</td>
                          <td class="aux_intable_td2"><textarea name="description" cols="32" rows="4" class="max-length-500">${reason.description}</textarea></td>
                        </tr>
                        <tr>
                          <td valign="top" class="aux_intable_td1">${key.seqNo}：</td>
                          <td class="aux_intable_td2"><input name="seqNo" type="text" class="int-range-0-32737" value="${reason.seqNo}" size="2" maxlength="5" /></td>
                        </tr>
                        </table>
                        </form>
                    </td>
                  </tr>
              </table></td>
            </tr>
        </table></td>
      </tr>
    </table>

    </td>
  </tr>
  <tr>
    <td class="window_footer"><table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0" id="copyMeter_submitAgain" style="display:show;">
          <tr>
            <td class="buttonOffLeft" id="btn1_41"></td>
            <td class="buttonOffMiddle" id="btn1_42" onClick="ajaxSubmitAgain();" onMouseOver="btn_change_over(4)" onMouseOut="btn_change_out(4)" onblur="btn_change(4)"><img src="${ctx}/images/ico_saveandnewfile.gif" alt="" width="14" height="14" border="0" align="absbottom"> ${key.saveAndAdd}</td>
            <td class="buttonOffRight" id="btn1_43"></td>
          </tr>
        </table></td>
        <td class="btn_between_four"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onClick="ajaxSubmit();" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onblur="btn_change(2)"><img src="${ctx}/images/ico_ok.gif" alt="" width="14" height="14" border="0" align="absbottom"> ${key.save}</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onClick="closeWin();" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)" onblur="btn_change(3)"><img src="${ctx}/images/ico_cancel.gif" alt="" width="14" height="14" border="0" align="absbottom"> ${key.close}</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
<script>
function init(editFlag){
	if(editFlag == 'add'){//add
		//must show saveAndAdd button
		$('copyMeter_title').innerText =  "${key.exceptionAddTitle}";
		$('copyMeter_submitAgain').style.display="";
		flag = "add";
	}else if(editFlag == 'update'){//update
		$('copyMeter_title').innerText = "${key.exceptionEditTitle}";
		$('copyMeter_submitAgain').style.display="none";
		flag = "update";
	}
	$('name').validateUrl = "${ctx}/house_partnershipAction.do?method=checkReasonByName";
	sourceValue=$('reasonForm').serialize();
}
</script>
</body>
</html>